#include "PathfinderComponent.h"

const HashedString PathfinderComponent::type("PathfinderComponent");
	
PathfinderComponent::PathfinderComponent( Entity* parent ) : IComponent(parent)
{
}
PathfinderComponent::PathfinderComponent( PathfinderComponent& o ) : IComponent(o)
{
	m_pathfinder = o.m_pathfinder; 
}
PathfinderComponent::~PathfinderComponent()
{
}

const HashedString& PathfinderComponent::Type()
{
	return type;
}
std::string PathfinderComponent::ToString() const
{
	char buffer[25];
	return std::string("WaypointListName=" + m_waypointListName + "CurrentWayPoint" + itoa(m_pathfinder->CurrentWaypoint(), buffer, 10));
}
bool PathfinderComponent::ToXML( tinyxml2::XMLPrinter& printer )
{
	printer.OpenElement("WaypointList");
	printer.PushAttribute("Name", m_waypointListName.c_str());
	printer.PushAttribute("CurrentWaypoint", m_pathfinder->CurrentWaypoint());
	printer.CloseElement();
	return true;
}
	
void PathfinderComponent::setWaypoints( std::string name, Pathing::Waypoint::Vector_t& waypoints )
{
	m_waypointListName = name;
	m_pathfinder = new Pathing::Pathfinder(waypoints);
}
Subject<Maths::Vector3D>& PathfinderComponent::getPosition()
{
	return m_pathfinder->getPosition();
}
void PathfinderComponent::BindTo( Subject<Maths::Vector3D>& location )
{
	m_position = new DoubleValueTrigger<Maths::Vector3D>(&location, &m_pathfinder->getPosition());
}
